package mongo

import (
	"sync"

	"gopkg.in/mgo.v2"
)

var (
	pools = sync.Map{}
)

func newMongo(DSN string) (*mgo.Session, error) {
	session, ok := pools.Load(DSN)
	if ok {
		return session.(*mgo.Session), nil
	} else {
		session, e := mgo.Dial(DSN)
		if e != nil {
			return nil, e
		}
		session.SetMode(mgo.Monotonic, true)
		pools.Store(DSN, session)

		return session, e
	}
}
